This project demonstrates my ability to use SQL for complex data analysis and derive meaningful business intelligence.
Our coffee chain has been expanding rapidly, and management needed a comprehensive understanding of our sales performance across different locations, products, and time periods. The goals of this analysis were to:
ALTER TABLE coffee_brand.coffee_shop_sales ADD COLUMN transaction_day DATE; UPDATE coffee_brand.coffee_shop_sales SET transaction_date = STR_TO_DATE(transaction_date, '%m/%d/%Y'); ALTER TABLE coffee_brand.coffee_shop_sales MODIFY COLUMN transaction_date DATE; UPDATE coffee_brand.coffee_shop_sales SET transaction_time = STR_TO_DATE(transaction_time, '%H:%i:%s'); ALTER TABLE coffee_brand.coffee_shop_sales MODIFY COLUMN transaction_time TIME;
To ensure accurate time-based analysis, I prepared the data by:
This standardization allows for more precise temporal analysis and easier querying of time-based data.
SELECT DATE_FORMAT(transaction_date, '%Y-%m') AS Month, ROUND(SUM(unit_price * transaction_qty),1) AS total_sales FROM coffee_brand.coffee_shop_sales GROUP BY DATE_FORMAT(transaction_date, '%Y-%m');
This query analyzes monthly sales trends by:
This information helps identify seasonal patterns and overall sales performance over time.
SELECT ROUND(AVG(transaction_qty*unit_price),2) as avg_of_a_transaction, store_location FROM coffee_brand.coffee_shop_sales GROUP BY store_location;
This analysis calculates the average transaction value for each store location, helping to:
SELECT product_category, product_type, ROUND(SUM(transaction_qty* unit_price),2) AS total_sales FROM coffee_brand.coffee_shop_sales GROUP BY product_category, product_type ORDER BY product_type ASC LIMIT 10;
This query identifies the top-selling product categories and types by:
This information is crucial for inventory management and marketing strategies.
SELECT ROUND(SUM(transaction_qty*unit_price),2) AS revenue, SUM(transaction_qty) AS quantity_sold, product_category FROM coffee_brand.coffee_shop_sales GROUP BY product_category;
This analysis provides insights into each product category's performance by:
This helps in understanding which categories are driving sales and which might need attention.
WITH sales_data AS ( SELECT product_type, SUM(transaction_qty) AS total_quantity_sold, AVG(SUM(transaction_qty)) OVER () AS avg_quantity_sold FROM coffee_brand.coffee_shop_sales GROUP BY product_type ) SELECT product_type, total_quantity_sold, avg_quantity_sold, CASE WHEN total_quantity_sold > avg_quantity_sold THEN 'Above Average' WHEN total_quantity_sold < avg_quantity_sold THEN 'Below Average' ELSE 'Average' END AS product_status FROM sales_data;
This advanced query categorizes products based on their sales performance:
This analysis helps identify star products and those that might need marketing or quality improvements.